﻿package net.wangit.demo.performance;

import net.wangit.MapList;
import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.support.UnitInterceptor;
import net.wangit.util.RandomUtil;

public class SortListPerformanceUI implements UnitInterceptor {

  public String intercept(ActionContext ac, Unit unit) throws Exception {
    MapList data = new MapList();
    int size = ac.getRequestParameterInt("performance.sort.size", 100);
    unit.getElement("size").setDefaultValue(Integer.toString(size));
    for (int i = 0; i < size; i++) {
      data.put(i, "a", RandomUtil.getRandomDoubleString(5, 2));
      String str = RandomUtil.getRandomString(9);
      data.put(i, "b", str);
      data.put(i, "c", str);
      data.put(i, "d", RandomUtil.getRandomInteger(9));
    }
    ((Unit) unit.getElement("list").getObject()).setData(data);
    return unit.write(ac);
  }

}
